# files of NPC
NVBOARD_SRC = $(NPC_HOME)/csrc/utils
NVBOARD_SRCS := $(shell find $(NVBOARD_SRC) -name "*.cc")
NVBOARD_INC = $(NEMU_HOME)/include
INC_PATH += $(shell llvm-config --libs)


NVBOARD_BUILD_DIR = $(NPC_HOME)/build
NVBOARD_OBJS := $(addprefix $(NVBOARD_BUILD_DIR)/, $(addsuffix .o, $(basename $(notdir $(NVBOARD_SRCS)))))

# The archive of NVBoard
NVBOARD_ARCHIVE = $(NVBOARD_BUILD_DIR)/disasm.o
CXXFLAGS += -MMD -O3
CXXFLAGS += $(shell llvm-config --cxxflags) -fPIE




$(NVBOARD_BUILD_DIR)/%.o: $(NVBOARD_SRC)/%.cc
	@echo + CXX "->" NPC_HOME/$(shell realpath $< --relative-to $(NPC_HOME))
	@mkdir -p $(dir $@)
	@$(CXX) $(CXXFLAGS) -I$(NVBOARD_INC) -c -o $@ $<


# Build the archive of NVBoard
$(NVBOARD_ARCHIVE): $(NVBOARD_OBJS)
	@echo + AR "->" $(shell realpath $@ --relative-to $(NPC_HOME))
	@ar rcs $(NVBOARD_ARCHIVE) $(NVBOARD_OBJS)

# Rule (`#include` dependencies): paste in `.d` files generated by gcc on `-MMD`
-include $(NVBOARD_OBJS:.o=.d)

.PHONY: nvboard-archive nvboard-clean

nvboard-archive: $(NVBOARD_ARCHIVE)

nvboard-clean:
	rm -rf $(NVBOARD_BUILD_DIR)
